package com.mm.controller;

import cn.hutool.json.JSONUtil;
import com.alipay.api.AlipayApiException;
import com.mm.config.AlipayTemplate;
import com.mm.config.PayVo;
import com.mm.plugin.logging.annotation.AopLogger;
import com.mm.plugin.logging.enums.BusinessType;
import com.mm.utils.ApiResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;

/**
 * @author wdx
 * @date 2021/1/22 11:06
 */
@RestController
@Validated
@Slf4j
public class PayController {

    @Autowired
    AlipayTemplate alipayTemplate;

    @GetMapping(value = "/pay", produces = "text/html")
    public String pay() throws AlipayApiException {
        PayVo vo = new PayVo();
        vo.setBody("ssss");
        vo.setOut_trade_no("ssss1111111");
        vo.setSubject("2020Mac pro");
        vo.setTotal_amount("0.01");
        return alipayTemplate.pay(vo);
    }

    @GetMapping("/success")
    public String success() {
        return "支付成功";
    }

    @GetMapping("/notify")
    @AopLogger(describe = "支付异步回调")
    public ApiResult notify(@NotBlank(message = "sds")String b, String d)  {

//        int a = 10/0;
        return ApiResult.success("sss");
    }

    @GetMapping("/notify1/{s}")
    @AopLogger(describe = "sssssss",type = BusinessType.QUERY)
    public ApiResult notify1(@PathVariable String s)  {
//        int a = 10/0;
        return ApiResult.success("ssdasdasff");
    }

    @PostMapping("/ceshi")
    @AopLogger(describe = "支付异步回调")
    public ApiResult ceshi(@RequestBody PayVo vo)  {
        log.info(JSONUtil.toJsonStr(vo));
//        int a = 10/0;
        return ApiResult.success(vo);
    }
}
